// run: $exec < bfdiff.in
// opt: 0
// flag: -g
//
// segment tree [l, r)
#include <iostream>
#include <algorithm>

struct line // horizontal
{
	int x1, x2, y;
	int delta;
};

bool operator<(line const & a, line const & b)
{
	return a.y < b.y;
}

int const maxn = 210000;
int discrete_x[maxn];
line lines[maxn];
int tot, ltot;
int n;

namespace segment_tree
{
	struct node
	{
		int cover, sum;
	} tree[4 * maxn];

	void push_up(int id, int l, int r)
	{
		if (tree[id].cover) {
			tree[id].sum = discrete_x[r - 1] - discrete_x[l - 1];
			return;
		}
		if (l + 1 == r)
			tree[id].sum = 0;
		else
			tree[id].sum = tree[id * 2].sum + tree[id * 2 + 1].sum;
	}

	void update(int id, int l, int r, int del, int tl = 1, int tr = tot)
	{
		if (l <= tl && tr <= r) {
			tree[id].cover += del;
			push_up(id, tl, tr);
			return;
		}
		int mid = (tl + tr) / 2;
		if (l < mid) update(id * 2 + 0, l, r, del, tl, mid);
		if (mid < r) update(id * 2 + 1, l, r, del, mid, tr);
		push_up(id, tl, tr);
	}

	int query()
	{
		return tree[1].sum;
	}
};

int discrete(int x)
{
	return std::lower_bound(discrete_x, discrete_x + tot, x) - discrete_x + 1;
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n;
	tot = 0; ltot = 0;
	for (int i = 0, x1, y1, x2, y2; i < n; i++) {
		std::cin >> x1 >> y1 >> x2 >> y2;
		if (x1 > x2) std::swap(x1, x2);
		if (y1 > y2) std::swap(y1, y2);
		discrete_x[tot++] = x1;
		discrete_x[tot++] = x2 + 1;
		lines[ltot++] = line{x1, x2 + 1, y1, 1};
		lines[ltot++] = line{x1, x2 + 1, y2 + 1, -1};
	}
	std::sort(discrete_x, discrete_x + tot);
	std::sort(lines, lines + ltot);
	tot = std::unique(discrete_x, discrete_x + tot) - discrete_x;

	long long ans = 0;
	int x1 = discrete(lines[0].x1), x2 = discrete(lines[0].x2);
	segment_tree::update(1, x1, x2, lines[0].delta);
	for (int i = 1; i < ltot; i++) {
		ans += segment_tree::query() * ((long long)lines[i].y - (long long)lines[i - 1].y);
		int x1 = discrete(lines[i].x1), x2 = discrete(lines[i].x2);
		segment_tree::update(1, x1, x2, lines[i].delta);
	}
	std::cout << ans << '\n';
}

